//push和pop
///push()向Array的末尾添加若干个元素，pop()把Array的最后一个元素删除
var a=[1,2];
a.push('A','B')  
console.log(a)  //[1,2,A,B]
a.pop()
console.log(a)  //[1,2,A]
a.pop();a.pop();a.pop();   //连续3次删除最后一个元素
console.log(a);   //[]

//unshift和shift
///unshift往Array首部添加若干个元素，shift把Array首个元素删除
var b=[1,2];
b.unshift('A','B');   
console.log(b)    //[A,B,1,2]
b.shift();
console.log(b);   //[B,1,2]
b.shift();b.shift();b.shift();
console.log(b)   //[]
b.shift()
console.log(b);   //空数组再减不会报错，而是返回underfined

//sort和reverse
///sort对元素进行默认排序，reverse对元素反转排序
var c=[1,25,65,5,9]
c.sort();
console.log(c);   //[1, 25, 5, 65, 9]
c.reverse();
console.log(c);    //[9, 65, 5, 25, 1]
var d=['A','C','F','B']
console.log(d.sort());    //["A", "B", "C", "F"]
console.log(d.reverse());     //["F", "C", "B", "A"]

//splice
///splice()方法可以从指定索引删除若干个元素，再从该位置添加若干个元素
var e=['A','B','C','D','E','F'];
e.splice(2,3,'a','b')   //从索引为2即C开始删除3个元素，再加上a，b两个元素
console.log(e)      //["A", "B", "a", "b", "F"]
///只删除，不添加
var r=['A','B','C']
r.splice(2,1)
console.log(r)  //[A,B]
///只添加，不删除
var t=['A','B','C','D','E','F'];
t.splice(2,0,'X','Y')
console.log(t)    //["A", "B", "X", "Y", "C", "D", "E", "F"]


//对数字进行从小到大的排序
var arr=[2,1,5,621,45,63]
arr.arrarr=function()
{
    for(var j=0;j<this.length;j++)
    {
        var item=this[j]
        var idx=0
        for(var i=j+1;i<this.length;i++)
        {
            if(this[i]<item)
            {
                item=this[i]
                idx=i
            }
        }
        if (this[j] !== item){
            var a=this[j]
            this[j]=this[idx]
            this[idx]=a
        }
        console.log(arr)
    }
}
arr.arrarr()

                                   